using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using limpalex.bbparser.Interfaces;

namespace limpalex.bbparser
{
    sealed class TagParameterList : IParameterList
    {
        private const string DefaultParameterName = "default";
        private const string ContentParameterName = "content";
        private readonly NameValueCollection _innerList;
        public string this[string key]
        {
            get { return _innerList[key]; }
            internal set { _innerList[key] = value; }
        }

        public IEnumerable GetParameterNames()
        {
            return _innerList.AllKeys;
        }

        public bool HasParameter(string name)
        {
            return Array.Exists(_innerList.AllKeys, s => s.Equals(name, StringComparison.CurrentCultureIgnoreCase));
        }

        public bool HasDefaultParameter
        {
            get { return HasParameter(DefaultParameterName); }
        }

        public bool HasContentParameter
        {
            get { return HasParameter(ContentParameterName); }
        }

        public string DefaultParameter
        {
            get { return this[DefaultParameterName]; }
            internal set { this[DefaultParameterName] = value; }
        }

        public string ContentParameter
        {
            get { return this[ContentParameterName]; }
            internal set { this[ContentParameterName] = value; }
        }

        string IParameterList.ContentParameterName
        {
            get
            {
                return ContentParameterName;
            }
        }

        string IParameterList.DefaultParameterName
        {
            get
            {
                return DefaultParameterName;
            }
        }

        public TagParameterList(NameValueCollection parameters)
        {
            if ( parameters == null )
                throw new ArgumentNullException("parameters", "");
            _innerList = parameters;
        }

        public TagParameterList()
        {
            _innerList = new NameValueCollection();
        }

        public void AddFromList(NameValueCollection list)
        {
            _innerList.Add(list);
        }
    }
}
